{% extends "grappelli/templates/admin/change_form.html" %}
{% load i18n admin_modify adminmedia %}

{% block stylesheets %}
    {{ block.super }}
     <style type="text/css">
          .level {
               background-color:#eeeeee;
               font-size:120%;
               border:1px solid;
               padding: 2px;
               margin: 2px;
               line-height: 23px;
          }
          
          .level_complete {
               background-color:rgb(0,255,0);
          }
          textarea {
               height: 30px !important;
          }
          .original {
               font-size:0px;
          }
          .inline-group .tabular tr.has_original td {
               padding-top: 1em !important;
          }
     </style>
{% endblock %}

{% block javascripts %}
    {{ block.super }}
     <script type="text/javascript">
          function check_levels() {
               checks = $('input').filter(function() {
                        return this.name.match(/check_.*/) 
                    });
               
               {% for level in levels %}
                    i = 0;
                    checks.each(function(index){
                    /* For each checkbox in all checkboxes*/
                         if ($(this).attr('checked') && $(this).attr('name').match(/check_{{ level|cut:" " }}_.*/) ) {
                              i = i + 1;
                         }
                    });
                    if ( i >= {{ level.max }} ) {
                         $('#level_{{ level|cut:" " }}').addClass('level_complete');
                    } else {
                         $('#level_{{ level|cut:" " }}').removeClass('level_complete');
                    }
               {% endfor %}
          }
          
          $(document).ready(function() {
               check_levels();
          });
     </script>
{% endblock %}


<!-- CONTENT
SWORD override -->
{% block content %}
    <div class="container-flexible">
        <div class="form-container">
            <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %} 
                <div>
                    <!-- Popup Hidden Field -->
                    {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
                    
                    <!-- Submit-Row -->
                    {% if save_on_top %}{% submit_row %}{% endif %}
                    
                    <!-- Errors -->
                    {% if errors %}
                        <p class="errornote">{% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}</p>
                        <ul class="errorlist">{% for error in adminform.form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
                    {% endif %}
                    
                    <!-- Fieldsets -->
                    {% for fieldset in adminform %}
                        {% include "admin/includes/fieldset.html" %}
                        <!--SWORD added check list-->
                        {% if fieldset.name == None %}
                                <fieldset class="module aligned ">
                                 <h2>Process Status</h2>
                                 <div class="form-row checklist">
                                       <div>
                                           {% for level in levels %}
                                                {% for check in level.checks %}
                                                     <input type="checkbox" name="check_{{ level|cut:" " }}_{{ check }}_{{ check.id }}" {% if check.checked %} checked="checked" {% endif %} onclick="check_levels()"/> {{ check }} <br/>
                                                {% endfor %}
                                                <span id="level_{{ level|cut:" " }}" class="level" name="level_{{ level|cut:" " }}"> {{ level }} </span> <br/>
                                           {% endfor %}
                                       </div>
                                </div>
                                </fieldset>
                         {% endif %}
                    {% endfor %}
                    
                    {% block after_field_sets %}{% endblock %}
                    
                    <!-- Inlines -->
                    {% for inline_admin_formset in inline_admin_formsets %}
                        {% include inline_admin_formset.opts.template %}
                    {% endfor %}
                    
                    {% block after_related_objects %}{% endblock %}
                    
                    <!-- Submit-Row -->
                    {% submit_row %}
                    
                    {% if adminform and add %}
                        {% block extrahead %}
                            <script type="text/javascript">
                                (function($){
                                    $(function(){
                                        try {
                                            // focus on first form-field
                                            $("#{{ adminform.first_field.auto_id }}, #{{ adminform.first_field.auto_id }}_0")
                                            .eq(0).focus();
                                        } catch(e) {}
                                    });
                                }(django.jQuery));
                            </script>
                        {% endblock %}
                    {% endif %}
                    
                    <!-- JS for prepopulated fields -->
                    {% prepopulated_fields_js %}
                    
                </div>
            </form>
        </div>
    </div>
{% endblock %}